<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
	<meta name="author" content="wangyupeng">
	<title>新建单位帐户</title>
	<script language="javascript" src="../script/print.js" type="text/javascript"></script>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>
	<!--动态js-->
	<script language="javascript" type="text/javascript">
	//页面加载方法
	var qt;	
	var companyUser;
	var resultData;				//子窗口可以从该数据中获取单位信息，以减少查询次数
	var cOrg;
	var isPrintView = false;
	function load(){
		Eui.showNavigation();
		setPages(["readcardview","createcompanydiv","createdeptdiv","detview"]);
		cOrg = Common.cOrg();
		createCompany()
	}
	
	//创建单位
	function createCompany(){
		switchPage("createcompanydiv");
		CardMgnt.customer.show("companycustomerdiv",null,CardMgnt.COMPANYALL,{isCreate:true});
		CardMgnt.cardUser.show("companyuserdiv",null,CardMgnt.COMPANYALL);
	}
	
	//保存单位客户帐户
	function saveCompany(){
		if (!checkForm(CardMgnt.customer.formName)) return;
		if (!checkForm(CardMgnt.cardUser.formName)) return;
		
		if (!showQuestion("是否保存单位帐户？")) return;
		var cc = CardMgnt.customer.get();
		if (!cc.checkIdno){
			var c = DWR.syncCall("customerService.getCompanyCustomerForCardUser",cc.idno,cc.idnoType);
			if (c){
				if (!showQuestion("档案已经存在，是否在该档案下继续创建客户资料？")){onCancel();return;}
				cc.id = c.id
			}
		}
		var cu = CardMgnt.cardUser.get();
		DWR.call("customerService.saveCompanyCustomerAndUser",cc,cu,function(result){
			showInformation("单位客户保存成功");
			var cu = result.cardUser;
			var c = result.companyCustomer;
			c.uniqueId = cu.uniqueId
			c.idnoTypeText = Common.getText("idno_type",c.idnoType)
			Common.showDetail("detview",c);
			switchPage("detview")
		});
	}
	function onCancel(){
		CardMgnt.resetForm(CardMgnt.customer.formName)
		CardMgnt.resetForm(CardMgnt.cardUser.formName)
	}
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="createcompanydiv">
		<div id="companycustomerdiv" class="form">
		</div>
		<div id="companyuserdiv" class="form">
		</div>
		<p>
			<button onclick="saveCompany()">保 存</button>
			<button onclick="onCancel()">取 消</button>
		</p>
	</div>
	<div id="detview" style="display:none;" class="form">
		<div class="formTitle">单位帐号信息</div>
		<table cellSpacing="0" cellPadding="4" width="100%" border="0"
			class="viewTable col3">
			<tr>
				<td width="50%"><label>名&nbsp;&nbsp;&nbsp;&nbsp;称</label> <span
					id="name"></span></td>
				<td width="50%"><label>客户编号</label> <span id="uniqueId"></span></td>
			</tr>
			<tr>
				<td><label>证件类型</label> <span id="idnoTypeText"></span></td>
				<td><label>证&nbsp;件&nbsp;号</label> <span id="idno"></span></td>
			</tr>
		</table>
	</div>
	</div>
</body>
</html>